home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / OpenGL 1.0 SDK / Source / Examples / aux / samples / cursor.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-05-18  |  3.1 KB  |  171 lines  |  [TEXT/CWIE]

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include "tk.h"
  5.  
  6.  
  7. GLenum rgb, doubleBuffer, directRender, windType;
  8. int windX, windY;
  9. int cursor;
  10. GLubyte shape[] = {
  11.     0x00, 0x00,
  12.     0x7F, 0xFE,
  13.     0x40, 0x02,
  14.     0x40, 0x02,
  15.     0x40, 0x02,
  16.     0x40, 0x02,
  17.     0x40, 0x02,
  18.     0x40, 0x02,
  19.     0x40, 0x02,
  20.     0x40, 0x02,
  21.     0x40, 0x02,
  22.     0x40, 0x02,
  23.     0x40, 0x02,
  24.     0x40, 0x02,
  25.     0x7F, 0xFE,
  26.     0x00, 0x00
  27. };
  28. GLubyte mask[] = {
  29.     0xFF, 0xFF,
  30.     0xFF, 0xFF,
  31.     0xFF, 0xFF,
  32.     0xE0, 0x07,
  33.     0xE0, 0x07,
  34.     0xE0, 0x07,
  35.     0xE0, 0x07,
  36.     0xE0, 0x07,
  37.     0xE0, 0x07,
  38.     0xE0, 0x07,
  39.     0xE0, 0x07,
  40.     0xE0, 0x07,
  41.     0xE0, 0x07,
  42.     0xFF, 0xFF,
  43.     0xFF, 0xFF,
  44.     0xFF, 0xFF
  45. };
  46.  
  47.  
  48. static void Init(void)
  49. {
  50.     int i;
  51.  
  52.     for (i = TK_BLACK; i <= TK_WHITE; i++) {
  53.     tkNewCursor(i, shape, mask, i, TK_WHITE, 0, 0);
  54.     }
  55.     for (i = TK_BLACK; i <= TK_WHITE; i++) {
  56.     tkNewCursor(i+TK_WHITE, shape, mask, TK_WHITE, i, 0, 0);
  57.     }
  58.     cursor = TK_BLACK;
  59.     tkSetCursor(cursor);
  60.     glClearColor(0.0, 0.0, 0.0, 0.0);
  61.     glClearIndex(0.0);
  62. }
  63.  
  64. static void Reshape(int width, int height)
  65. {
  66.  
  67.     windX = width;
  68.     windY = height;
  69.     glViewport(0, 0, windX, windY);
  70.  
  71.     glMatrixMode(GL_PROJECTION);
  72.     glLoadIdentity();
  73.     gluOrtho2D(0, windX, 0, windY);
  74.     glMatrixMode(GL_MODELVIEW);
  75. }
  76.  
  77. static GLenum Key(int key, GLenum mask)
  78. {
  79.  
  80.     switch (key) {
  81.       case TK_ESCAPE:
  82.         tkQuit();
  83.       case TK_SPACE:
  84.     cursor++;
  85.     if (cursor > TK_WHITE*2) {
  86.         cursor = TK_BLACK;
  87.     }
  88.     tkSetCursor(cursor);
  89.       default:
  90.     return GL_FALSE;
  91.     }
  92.     return GL_TRUE;
  93. }
  94.  
  95. static void Draw(void)
  96. {
  97.  
  98.     glClear(GL_COLOR_BUFFER_BIT);
  99.  
  100.     glBegin(GL_POLYGON);
  101.     TK_SETCOLOR(windType, TK_BLACK);
  102.     glVertex2i(0, 0);
  103.     TK_SETCOLOR(windType, TK_RED);
  104.     glVertex2i(windX, 0);
  105.     TK_SETCOLOR(windType, TK_GREEN);
  106.     glVertex2i(windX, windY);
  107.     TK_SETCOLOR(windType, TK_BLUE);
  108.     glVertex2i(0, windY);
  109.     glEnd();
  110.  
  111.     glFlush();
  112. }
  113.  
  114. static GLenum Args(int argc, char **argv)
  115. {
  116.     GLint i;
  117.  
  118.     rgb = GL_TRUE;
  119.     doubleBuffer = GL_FALSE;
  120.     directRender = GL_TRUE;
  121.  
  122.     for (i = 1; i < argc; i++) {
  123.     if (strcmp(argv[i], "-ci") == 0) {
  124.         rgb = GL_FALSE;
  125.     } else if (strcmp(argv[i], "-rgb") == 0) {
  126.         rgb = GL_TRUE;
  127.     } else if (strcmp(argv[i], "-sb") == 0) {
  128.         doubleBuffer = GL_FALSE;
  129.     } else if (strcmp(argv[i], "-db") == 0) {
  130.         doubleBuffer = GL_TRUE;
  131.     } else if (strcmp(argv[i], "-dr") == 0) {
  132.         directRender = GL_TRUE;
  133.     } else if (strcmp(argv[i], "-ir") == 0) {
  134.         directRender = GL_FALSE;
  135.     } else {
  136.         printf("%s (Bad option).\n", argv[i]);
  137.         return GL_FALSE;
  138.     }
  139.     }
  140.     return GL_TRUE;
  141. }
  142.  
  143. void main(int argc, char **argv)
  144. {
  145.  
  146.     if (Args(argc, argv) == GL_FALSE) {
  147.     tkQuit();
  148.     }
  149.  
  150.     windX = 300;
  151.     windY = 300;
  152.     tkInitPosition(30, 60, windX, windY);
  153.  
  154.     windType = (rgb) ? TK_RGB : TK_INDEX;
  155.     windType |= (doubleBuffer) ? TK_DOUBLE : TK_SINGLE;
  156.     windType |= (directRender) ? TK_DIRECT : TK_INDIRECT;
  157.     tkInitDisplayMode(windType);
  158.  
  159.     if (tkInitWindow("Cursor Test") == GL_FALSE) {
  160.     tkQuit();
  161.     }
  162.  
  163.     Init();
  164.  
  165.     tkExposeFunc(Reshape);
  166.     tkReshapeFunc(Reshape);
  167.     tkKeyDownFunc(Key);
  168.     tkDisplayFunc(Draw);
  169.     tkExec();
  170. }
  171.